package com.julian.decoratorPattern;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

public class LowerCaseInputStream extends FilterInputStream {
    public LowerCaseInputStream(InputStream in) {
        super(in);
    }

    @Override
    /**
     * 按字节读取
     */
    public int read() throws IOException{
        int c = super.read();
        return (c == -1 ? c : Character.toLowerCase((char) c));
    }

    @Override
    /**
     * 按字节数组读
     */
    public int read(byte[] b, int off, int len) throws IOException {
        int result = super.read(b,off,len);
        for(int i = off; i < off + len; i++){
            b[i] = (byte)Character.toLowerCase((char) b[i]);
        }
        return result;
    }
}
